/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrameOpcao.java
 *
 * Created on 05/07/2011, 22:21:11
 */
package br.com.GUI.cadastro;

import br.com.classes.Caixa;
import br.com.dao.CaixaDao;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 *
 * @author Levi&Mara
 */
public class FrameCaixa extends javax.swing.JFrame {

    /**
     * Creates new form FrameOpcao
     */
    int num = 0;
    int codigo_caixa;

    public FrameCaixa() {
        initComponents();
        CarregarCaixa();
    }

    public class LetraMaiuscula extends PlainDocument {

        @Override
        public void insertString(int offset, String str, AttributeSet attr)
                throws BadLocationException {
            super.insertString(offset, str.toUpperCase(), attr);
        }
    }

    public void CarregarCaixa() {
        CaixaDao cdao = new CaixaDao();
        List<Caixa> lista = cdao.ListarCaixa();
        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCaixa.getModel();
        modelo.setRowCount(0);

        for (Caixa c : lista) {
            modelo.addRow(new Object[]{c.getCod_caixa(), c.getCaixa(), c.getCxRazaoSocial(), c.getCxEndereco(), c.getCxCidade(), c.getCxRegistro(), c.getCxRespLegal(), c.getCxContador(), c.getCxNomeEmp()});
        }

        jTableConsultaCaixa.setModel(modelo);
    }

    public void CarregarLetraCaixa() {
        String caixa = jTextField2.getText();

        CaixaDao cdao = new CaixaDao();
        List<Caixa> lista = cdao.ProcurarCaixaLetra(caixa);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCaixa.getModel();
        modelo.setRowCount(0);

        for (Caixa c : lista) {
            modelo.addRow(new Object[]{c.getCod_caixa(), c.getCaixa(), c.getCxRazaoSocial(), c.getCxEndereco(), c.getCxCidade(), c.getCxRegistro(), c.getCxRespLegal(), c.getCxContador(), c.getCxNomeEmp()});
        }

        jTableConsultaCaixa.setModel(modelo);
    }

    public void BuscarLimiteAnterior() {
        num = num - 10;

        CaixaDao cdao = new CaixaDao();
        List<Caixa> lista = cdao.BuscarLimite(num);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCaixa.getModel();
        modelo.setRowCount(0);

        for (Caixa c : lista) {
            modelo.addRow(new Object[]{c.getCod_caixa(), c.getCaixa(), c.getCxRazaoSocial(), c.getCxEndereco(), c.getCxCidade(), c.getCxRegistro(), c.getCxRespLegal(), c.getCxContador(), c.getCxNomeEmp()});
        }
        jTableConsultaCaixa.setModel(modelo);
        if (lista.size() < 10) {
            jButtonVoltar.setEnabled(false);
        }
    }

    public void BuscarLimiteProximo() {
        num = num + 10;

        CaixaDao cdao = new CaixaDao();
        List<Caixa> lista = cdao.BuscarLimite(num);

        DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCaixa.getModel();
        modelo.setRowCount(0);

        for (Caixa c : lista) {
            modelo.addRow(new Object[]{c.getCod_caixa(), c.getCaixa(), c.getCxRazaoSocial(), c.getCxEndereco(), c.getCxCidade(), c.getCxRegistro(), c.getCxRespLegal(), c.getCxContador(), c.getCxNomeEmp()});
        }
        jTableConsultaCaixa.setModel(modelo);
        if (lista.size() < 10) {
            jButtonAvancar.setEnabled(false);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonCadastrar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableConsultaCaixa = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButtonAvancar = new javax.swing.JButton();
        jButtonVoltar = new javax.swing.JButton();
        jButtonEditar = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButtonRemover = new javax.swing.JButton();
        jLabelCaixa = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabelNome = new javax.swing.JLabel();
        jTextFieldNome = new javax.swing.JTextField();
        jLabelRazaoSocial = new javax.swing.JLabel();
        jTextFieldRazaoSocial = new javax.swing.JTextField();
        jLabelCidade = new javax.swing.JLabel();
        jTextFieldCidade = new javax.swing.JTextField();
        jLabelResponsavelLegal = new javax.swing.JLabel();
        jTextFieldResponsavel = new javax.swing.JTextField();
        jTextFieldEndereço = new javax.swing.JTextField();
        jLabelEndereço = new javax.swing.JLabel();
        jLabelRegCivil = new javax.swing.JLabel();
        jTextFieldRegCivil = new javax.swing.JTextField();
        jLabelContador = new javax.swing.JLabel();
        jTextFieldContador = new javax.swing.JTextField();
        jLabelEmpresa = new javax.swing.JLabel();
        jTextFieldEmpresa = new javax.swing.JTextField();
        jButtonLimparCaixa = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jButtonCadastrar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCadastrar.setText("Cadastrar");
        jButtonCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCadastrarActionPerformed(evt);
            }
        });

        jTableConsultaCaixa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Caixa", "Razão Social", "Endereço", "Cidade", "Registro Civil", "Responsavel", "Contador", "Empresa"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableConsultaCaixa.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTableConsultaCaixa);
        jTableConsultaCaixa.getColumnModel().getColumn(0).setResizable(false);
        jTableConsultaCaixa.getColumnModel().getColumn(0).setPreferredWidth(50);
        jTableConsultaCaixa.getColumnModel().getColumn(2).setResizable(false);
        jTableConsultaCaixa.getColumnModel().getColumn(3).setResizable(false);
        jTableConsultaCaixa.getColumnModel().getColumn(4).setResizable(false);
        jTableConsultaCaixa.getColumnModel().getColumn(5).setResizable(false);
        jTableConsultaCaixa.getColumnModel().getColumn(6).setResizable(false);
        jTableConsultaCaixa.getColumnModel().getColumn(7).setResizable(false);
        jTableConsultaCaixa.getColumnModel().getColumn(8).setResizable(false);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/search[1].png"))); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Pesquisar Caixa:");

        jButtonAvancar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/next[2].png"))); // NOI18N
        jButtonAvancar.setBorder(null);
        jButtonAvancar.setContentAreaFilled(false);
        jButtonAvancar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/next[2]over.png"))); // NOI18N
        jButtonAvancar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAvancarActionPerformed(evt);
            }
        });

        jButtonVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/back[2].png"))); // NOI18N
        jButtonVoltar.setBorder(null);
        jButtonVoltar.setContentAreaFilled(false);
        jButtonVoltar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/back[2]over.png"))); // NOI18N
        jButtonVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVoltarActionPerformed(evt);
            }
        });

        jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png"))); // NOI18N
        jButtonEditar.setBorder(null);
        jButtonEditar.setContentAreaFilled(false);
        jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png"))); // NOI18N
        jButtonEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEditarActionPerformed(evt);
            }
        });

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh.png"))); // NOI18N
        jButton8.setBorder(null);
        jButton8.setContentAreaFilled(false);
        jButton8.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/refresh[2]over.png"))); // NOI18N
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButtonRemover.setBackground(null);
        jButtonRemover.setForeground(null);
        jButtonRemover.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete[5].png"))); // NOI18N
        jButtonRemover.setBorder(null);
        jButtonRemover.setBorderPainted(false);
        jButtonRemover.setContentAreaFilled(false);
        jButtonRemover.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete[5]over.png"))); // NOI18N
        jButtonRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRemoverActionPerformed(evt);
            }
        });

        jLabelCaixa.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabelCaixa.setText("Caixa");

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });
        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField2KeyReleased(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabelNome.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelNome.setText("*Nome:");

        jTextFieldNome.setDocument(new LetraMaiuscula());

        jLabelRazaoSocial.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelRazaoSocial.setText("Razão Social: ");

        jTextFieldRazaoSocial.setDocument(new LetraMaiuscula());
        jTextFieldRazaoSocial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldRazaoSocialActionPerformed(evt);
            }
        });

        jLabelCidade.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCidade.setText("Cidade:");

        jTextFieldCidade.setDocument(new LetraMaiuscula());

        jLabelResponsavelLegal.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelResponsavelLegal.setText("Responsavel Legal:");

        jTextFieldResponsavel.setDocument(new LetraMaiuscula());

        jTextFieldEndereço.setDocument(new LetraMaiuscula());

        jLabelEndereço.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelEndereço.setText("Endereço:");

        jLabelRegCivil.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelRegCivil.setText("Registro Civil:");

        jTextFieldRegCivil.setDocument(new LetraMaiuscula());

        jLabelContador.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelContador.setText("Contador: ");

        jTextFieldContador.setDocument(new LetraMaiuscula());

        jLabelEmpresa.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelEmpresa.setText("Nome da Empresa:");

        jTextFieldEmpresa.setDocument(new LetraMaiuscula());

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelEndereço)
                            .addComponent(jLabelRegCivil)
                            .addComponent(jLabelRazaoSocial)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addComponent(jLabelNome, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldRegCivil)
                    .addComponent(jTextFieldEndereço)
                    .addComponent(jTextFieldRazaoSocial)
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelContador, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelResponsavelLegal, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelCidade, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelEmpresa, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldCidade)
                    .addComponent(jTextFieldResponsavel, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addComponent(jTextFieldEmpresa)
                    .addComponent(jTextFieldContador))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNome, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCidade))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelRazaoSocial))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldEndereço, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelEndereço))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldRegCivil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelRegCivil)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldResponsavel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelResponsavelLegal))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelEmpresa))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldContador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelContador)))))
        );

        jButtonLimparCaixa.setText("Limpar");
        jButtonLimparCaixa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimparCaixaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabelCaixa)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 479, Short.MAX_VALUE)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 763, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButtonLimparCaixa)
                                        .addGap(234, 234, 234)
                                        .addComponent(jButtonVoltar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButtonEditar)
                                        .addGap(2, 2, 2)
                                        .addComponent(jButton8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButtonRemover)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButtonAvancar)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButtonCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(4, 4, 4))
                    .addComponent(jLabel5)
                    .addComponent(jLabelCaixa))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(49, 49, 49)
                        .addComponent(jLabel1)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton8)
                            .addComponent(jButtonRemover, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonAvancar)
                            .addComponent(jButtonEditar)
                            .addComponent(jButtonVoltar)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jButtonLimparCaixa))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCadastrarActionPerformed

        if (jTextFieldNome.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Favor preencher os campos!");
        } else {

            try {
                if (jLabelCaixa.getText().equals("Caixa")) {
                    Caixa c = new Caixa();
                    CaixaDao cdao = new CaixaDao();
                    //int codcaixa = cdao.UltimoCodCaixa();

                    DefaultTableModel modelo = (DefaultTableModel) jTableConsultaCaixa.getModel();

                    c.setCaixa(jTextFieldNome.getText());
                    c.setCxRazaoSocial(jTextFieldRazaoSocial.getText());
                    c.setCxCidade(jTextFieldCidade.getText());
                    c.setCxEndereco(jTextFieldEndereço.getText());
                    c.setCxRespLegal(jTextFieldResponsavel.getText());
                    c.setCxRegistro(jTextFieldRegCivil.getText());
                    c.setCxNomeEmp(jTextFieldEmpresa.getText());
                    c.setCxContador(jTextFieldContador.getText());


                    cdao.CadastrarCaixa(c);
                    //BuscarLimiteProximo();
                    //modelo.addRow(new Object[]{codcaixa, c.getCaixa()});
                    CarregarCaixa();
                    JOptionPane.showMessageDialog(this, "Cadastrado com sucesso");
                    jTableConsultaCaixa.setModel(modelo);

                    jTextFieldNome.setText("");
                    jTextFieldRazaoSocial.setText("");
                    jTextFieldCidade.setText("");
                    jTextFieldEndereço.setText("");
                    jTextFieldResponsavel.setText("");
                    jTextFieldRegCivil.setText("");
                    jTextFieldEmpresa.setText("");
                    jTextFieldContador.setText("");
                } else {
                    Object[] OPTIONS = {"Sim", "Não"};

                    int I = JOptionPane.showOptionDialog(null, "Tem certeza que deseja alterar o registro?", "Alterar", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, OPTIONS, OPTIONS[0]);
                    if (I == JOptionPane.YES_OPTION) {
                        Caixa c = new Caixa();
                        c.setCod_caixa(codigo_caixa);
                        c.setCaixa(jTextFieldNome.getText());
                        c.setCxRazaoSocial(jTextFieldRazaoSocial.getText());
                        c.setCxCidade(jTextFieldCidade.getText());
                        c.setCxEndereco(jTextFieldEndereço.getText());
                        c.setCxRespLegal(jTextFieldResponsavel.getText());
                        c.setCxRegistro(jTextFieldRegCivil.getText());
                        c.setCxNomeEmp(jTextFieldEmpresa.getText());
                        c.setCxContador(jTextFieldContador.getText());


                        //c.setSaldo_atual(c.getSaldo_atual());
                        JOptionPane.showMessageDialog(this, "Cadastrado com sucesso!");
                        CaixaDao cdao = new CaixaDao();
                        cdao.AlterarCaixa(c);

                        jTextFieldNome.setText("");
                        jTextFieldRazaoSocial.setText("");
                        jTextFieldCidade.setText("");
                        jTextFieldEndereço.setText("");
                        jTextFieldResponsavel.setText("");
                        jTextFieldRegCivil.setText("");
                        jTextFieldEmpresa.setText("");
                        jTextFieldContador.setText("");
                        jLabelCaixa.setText("Caixa");
                        jButtonCadastrar.setText("Cadastrar");
                       jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png")));
                       jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png")));


                    }
                    CarregarCaixa();
                }

            } catch (Exception e) {
                System.out.println("1 - " + e.getMessage());
            }
        }
    }//GEN-LAST:event_jButtonCadastrarActionPerformed

    private void jButtonAvancarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAvancarActionPerformed
    
        BuscarLimiteProximo();
        jButtonVoltar.setEnabled(true);
}//GEN-LAST:event_jButtonAvancarActionPerformed

    private void jButtonVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVoltarActionPerformed
        
        BuscarLimiteAnterior();
        jButtonAvancar.setEnabled(true);
}//GEN-LAST:event_jButtonVoltarActionPerformed

    private void jButtonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditarActionPerformed
   
        if (jTableConsultaCaixa.getSelectedRow() >= 0) {
            if (jLabelCaixa.getText().equals("Caixa")){    
                jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/removeicon.png")));
                jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/removeicon.png")));
                int k = jTableConsultaCaixa.getSelectedRow();
                codigo_caixa = (Integer) jTableConsultaCaixa.getValueAt(k, 0);

                CaixaDao udao = new CaixaDao();
                Caixa u = udao.PesquisarCaixa(codigo_caixa);

                jTextFieldNome.setText(u.getCaixa());
                jTextFieldRazaoSocial.setText(u.getCxRazaoSocial());
                jTextFieldCidade.setText(u.getCxCidade());
                jTextFieldEndereço.setText(u.getCxEndereco());
                jTextFieldResponsavel.setText(u.getCxRespLegal());
                jTextFieldRegCivil.setText(u.getCxRegistro());
                jTextFieldEmpresa.setText(u.getCxNomeEmp());
                jTextFieldContador.setText(u.getCxContador());
                jLabelCaixa.setText("Alterar Caixa");
                jButtonCadastrar.setText("Alterar");
            } else {
                jTextFieldNome.setText("");
                jTextFieldRazaoSocial.setText("");
                jTextFieldCidade.setText("");
                jTextFieldEndereço.setText("");
                jTextFieldResponsavel.setText("");
                jTextFieldRegCivil.setText("");
                jTextFieldEmpresa.setText("");
                jTextFieldContador.setText("");
                jLabelCaixa.setText("Caixa");
                jButtonCadastrar.setText("Cadastrar");

                jButtonEditar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil[2]over.png")));
                jButtonEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pencil.png")));
            }
        } else {
            JOptionPane.showMessageDialog(this, "Favor selecionar o Caixa para ser alterado");
        }

}//GEN-LAST:event_jButtonEditarActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        CarregarCaixa();
        jButtonAvancar.setEnabled(true);
}//GEN-LAST:event_jButton8ActionPerformed

    private void jButtonRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRemoverActionPerformed
 if (jTableConsultaCaixa.getSelectedRow() >= 0) {
        int linha = jTableConsultaCaixa.getSelectedRow();
        Object[] OPTIONS = {"Sim", "Não"};
        String caixa = jTableConsultaCaixa.getValueAt(linha, 1).toString();
        CaixaDao cdao = new CaixaDao();
        Caixa c = new Caixa();
        c.setCaixa(caixa);
        try {
            int I = JOptionPane.showOptionDialog(null, "Tem certeza que deseja excluir o registro?", "Excluir", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, OPTIONS, OPTIONS[0]);
            if (I == JOptionPane.YES_OPTION) {

                cdao.DeletarCaixa(c);
                JOptionPane.showMessageDialog(this, "Excluído com sucesso!");
                CarregarCaixa();
            }
        } catch (Exception e) {
            System.out.println("1 - " + e.getMessage());
        }}else {
           JOptionPane.showMessageDialog(null, "Por favor selecione um caixa para ser excluido!");
       }   

}//GEN-LAST:event_jButtonRemoverActionPerformed

    private void jTextField2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyReleased
         
        CarregarLetraCaixa();
    }//GEN-LAST:event_jTextField2KeyReleased

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
         
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jTextFieldRazaoSocialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldRazaoSocialActionPerformed
         
    }//GEN-LAST:event_jTextFieldRazaoSocialActionPerformed

    private void jButtonLimparCaixaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimparCaixaActionPerformed
         
        jTextFieldNome.setText("");
        jTextFieldRazaoSocial.setText("");
        jTextFieldCidade.setText("");
        jTextFieldEndereço.setText("");
        jTextFieldResponsavel.setText("");
        jTextFieldRegCivil.setText("");
        jTextFieldEmpresa.setText("");
        jTextFieldContador.setText("");
    }//GEN-LAST:event_jButtonLimparCaixaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrameCaixa().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButtonAvancar;
    private javax.swing.JButton jButtonCadastrar;
    private javax.swing.JButton jButtonEditar;
    private javax.swing.JButton jButtonLimparCaixa;
    private javax.swing.JButton jButtonRemover;
    private javax.swing.JButton jButtonVoltar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabelCaixa;
    private javax.swing.JLabel jLabelCidade;
    private javax.swing.JLabel jLabelContador;
    private javax.swing.JLabel jLabelEmpresa;
    private javax.swing.JLabel jLabelEndereço;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelRazaoSocial;
    private javax.swing.JLabel jLabelRegCivil;
    private javax.swing.JLabel jLabelResponsavelLegal;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableConsultaCaixa;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextFieldCidade;
    private javax.swing.JTextField jTextFieldContador;
    private javax.swing.JTextField jTextFieldEmpresa;
    private javax.swing.JTextField jTextFieldEndereço;
    private javax.swing.JTextField jTextFieldNome;
    private javax.swing.JTextField jTextFieldRazaoSocial;
    private javax.swing.JTextField jTextFieldRegCivil;
    private javax.swing.JTextField jTextFieldResponsavel;
    // End of variables declaration//GEN-END:variables
}
